import asyncio
import functools
import time
from typing import Callable, Any


def async_timed():
    def wrapper(func: Callable):
        @functools.wraps(func)
        async def wrapped(*args: Any, **kwargs: Any) -> Any:
            print(f"有参数{args}，{kwargs}的函数{func}开始运行")
            start = time.time()
            try:
                return await func(*args, **kwargs)
            finally:
                end = time.time()
                total = end - start
                print(f"函数{func}总共花费时间：{total}s")

        return wrapped

    return wrapper


@async_timed()
async def delay(seconds):
    print(f"开始{seconds}s的延迟...")
    await asyncio.sleep(seconds)
    print(f"结束{seconds}s的延迟...")
    return seconds


@async_timed()
async def main():
    task1 = asyncio.create_task(delay(2))
    task2 = asyncio.create_task(delay(3))

    await task1
    await task2


asyncio.run(main())
